/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef LIB2D_OBJECTS_TEXTSPRITEREP_H
#define LIB2D_OBJECTS_TEXTSPRITEREP_H

#include "font/Proportional.h"
#include <SharedRep.h>
#include "ImageSimple.h"
#include <resource/Manager.h>
#include <xml/Stream.h>

namespace liba
{
namespace lib2d
{
namespace objects
{

class TextSpriteRep :
	public Shared< filesystem::String, font::Proportional >,
	private xml::ObjectANSI
{
	AutoPtr< ImageSimple > image;
public:
	explicit TextSpriteRep( const filesystem::String & name )
	{
		AutoPtr<resource::Resource> res = resource::Manager::create_resource( name );
		if( !xml::StreamResource(res).load( &xml::Root( this, "TextSprite" ) ) )
			return;	//TODO throw gluck
	}
	virtual bool on_attribute( xml::Provider * prov, const std::string & name, const std::string & value )
	{
		if( name == "Font" )
		{
			load_rep( value );
			return true;
		}
		if( name == "Image" )
		{
			image = new ImageSimple( value );
			return true;
		}

		return false;
	}
	const font::Proportional * get_font()const
	{
		return get_rep();
	}

	ImageSimple * get_image()const
	{
		return image;
	}
};

} //namespace objects
} //namespace lib2d
} //namespace liba

using namespace liba;

#endif //LIB2D_OBJECTS_TEXTSPRITEREP_H